{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Determine if a Cell Is Reachable at a Given Time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isReachableAtTime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断能否在给定时间到达单元格"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你四个整数 <code>sx</code>、<code>sy</code>、<code>fx</code>、<code>fy</code>&nbsp; 以及一个 <strong>非负整数</strong> <code>t</code> 。</p>\n",
    "\n",
    "<p>在一个无限的二维网格中，你从单元格 <code>(sx, sy)</code> 开始出发。每一秒，你 <strong>必须</strong> 移动到任一与之前所处单元格相邻的单元格中。</p>\n",
    "\n",
    "<p>如果你能在 <strong>恰好 </strong><code>t</code><strong> 秒</strong> 后到达单元格<em> </em><code>(fx, fy)</code> ，返回 <code>true</code> ；否则，返回&nbsp; <code>false</code> 。</p>\n",
    "\n",
    "<p>单元格的 <strong>相邻单元格</strong> 是指该单元格周围与其至少共享一个角的 8 个单元格。你可以多次访问同一个单元格。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong class=\"example\">示例 1：</strong></p>\n",
    "<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/08/05/example2.svg\" style=\"width: 443px; height: 243px;\" />\n",
    "<pre>\n",
    "<strong>输入：</strong>sx = 2, sy = 4, fx = 7, fy = 7, t = 6\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>从单元格 (2, 4) 开始出发，穿过上图标注的单元格，可以在恰好 6 秒后到达单元格 (7, 7) 。 \n",
    "</pre>\n",
    "\n",
    "<p><strong class=\"example\">示例 2：</strong></p>\n",
    "<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/08/05/example1.svg\" style=\"width: 383px; height: 202px;\" />\n",
    "<pre>\n",
    "<strong>输入：</strong>sx = 3, sy = 1, fx = 7, fy = 3, t = 3\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>从单元格 (3, 1) 开始出发，穿过上图标注的单元格，至少需要 4 秒后到达单元格 (7, 3) 。 因此，无法在 3 秒后到达单元格 (7, 3) 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= sx, sy, fx, fy &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>0 &lt;= t &lt;= 10<sup>9</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [determine-if-a-cell-is-reachable-at-a-given-time](https://leetcode.cn/problems/determine-if-a-cell-is-reachable-at-a-given-time/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [determine-if-a-cell-is-reachable-at-a-given-time](https://leetcode.cn/problems/determine-if-a-cell-is-reachable-at-a-given-time/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['2\\n4\\n7\\n7\\n6', '3\\n1\\n7\\n3\\n3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        dx = abs(fx - sx)\n",
    "        dy = abs(fy - sy)\n",
    "        min_dis = min(dx, dy) + abs(dx - dy)\n",
    "        if t >= min_dis:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if fx == sx and fy == sy:\n",
    "            return t != 1\n",
    "        return max(abs(fx - sx), abs(fy - sy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        min_l = max(abs(fx - sx), abs(fy - sy))\n",
    "        if min_l == 0 and t == 1:\n",
    "            return False\n",
    "        else:\n",
    "            return t >= min_l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx = abs(sx-fx)\n",
    "        dy = abs(sy-fy)\n",
    "        return t>=max(dx, dy) if dx or dy else t!=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        xx = abs(sx - fx)\n",
    "        yy = abs(sy - fy)\n",
    "        diff = abs(xx - yy)\n",
    "        if xx == yy == 0:\n",
    "            return t != 1\n",
    "        \n",
    "        return min(xx,yy) + diff <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        a = min(abs(fx-sx), abs(fy-sy))\n",
    "        b = max(abs(fx-sx), abs(fy-sy))\n",
    "        if a == b == 0:\n",
    "            return t != 1\n",
    "        c = max(a,b)\n",
    "        return c<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return abs(sx - fx) <= t and abs(sy - fy) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx = abs(sx - fx)\n",
    "        dy = abs(sy - fy)\n",
    "        hi = max(dx, dy)\n",
    "        if hi == 0:\n",
    "            return t != 1\n",
    "        return t >= hi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy :\n",
    "            return t != 1\n",
    "        step = min(abs(sx - fx),abs(sy - fy))\n",
    "        step += max(abs(sx - fx),abs(sy - fy)) - step\n",
    "        return t >= step"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        dx, dy = abs(fx-sx), abs(fy-sy)\n",
    "        if t < dx or t < dy:\n",
    "            return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dy=abs(fy-sy)\n",
    "        dx=abs(fx-sx)\n",
    "        dis = max(dx,dy)\n",
    "        if dx==0 and dy==0 and t==1:\n",
    "            return False\n",
    "        if t<dis:\n",
    "            return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy: return t != 1\n",
    "        diff1, diff2 = abs(sx-fx), abs(sy-fy)\n",
    "        return t >= max(diff1, diff2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        ans = 0\n",
    "        if sx == fx and sy == fy:\n",
    "            if t == 1:\n",
    "                return False\n",
    "            return True\n",
    "            \n",
    "        if abs(sx-fx) <= abs(sy-fy):\n",
    "            ans += abs(sx-fx) + abs(abs(sy-fy) - abs(sx-fx))\n",
    "        else:\n",
    "            ans += abs(sy-fy) + abs(abs(sx-fx) - abs(sy-fy))\n",
    "        if ans <= t:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        \n",
    "        tx,ty=abs(fx-sx),abs(fy-sy)\n",
    "        if tx==0 and ty==0 and t==1:return False\n",
    "        \n",
    "        return min(tx,ty)+abs(ty-tx)<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        a = abs(fx-sx)\n",
    "        b = abs(fy-sy)\n",
    "        min1 = max(a,b)\n",
    "        if min1 == 0:\n",
    "            return t!=1\n",
    "        return t >= min1\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "\n",
    "        if sx == fx and sy ==fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        mi = max(abs(sx - fx), abs(sy - fy))\n",
    "        return mi <= t\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return (t != 1)\n",
    "        elif sx == fx:\n",
    "            dis = abs(sy - fy)\n",
    "        elif sy == fy:\n",
    "            dis = abs(sx - fx)\n",
    "        else:\n",
    "            dis = max(abs(sx - fx), abs(sy - fy))\n",
    "        return dis <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        diagonal = min(abs(sy - fy), abs(sx - fx))\n",
    "        line = max(abs(sy - fy), abs(sx - fx)) - diagonal\n",
    "        if diagonal + line > t:\n",
    "            return False\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx-fx), abs(sy-fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if (sx, sy) == (fx, fy):\n",
    "            if t == 1:\n",
    "                return False\n",
    "            else:\n",
    "                return True\n",
    "        else:\n",
    "            lb = max(abs(fx - sx), abs(fy - sy))\n",
    "            return t >= lb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        \"\"\"\n",
    "        https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time/solutions/4024786/java-c-python-o-1/\n",
    "        检查我们需要的最小步长 = max（abs（sx - fx），abs（sy - fy））。\n",
    "        如果 need > 0，则检查 t 是否 >= need。\n",
    "        如果我们能更早到达，就可以在其相邻单元格附近停留。\n",
    "        如果 need == 0，目标单元格就是起始单元格。\n",
    "        如果 t == 1，我们将离开当前单元格，无法到达。\n",
    "        否则，我们可以回到起始单元格。\n",
    "        \"\"\"\n",
    "        need = max(abs(sx - fx), abs(sy - fy))\n",
    "        return t >= need if need else t != 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        # 计算出最快到达的时间\n",
    "        min_t = max(abs(fy-sy), abs(fx-sx))\n",
    "\n",
    "        if min_t>t:\n",
    "            return False\n",
    "        elif min_t==0 and t==1:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy==fy:\n",
    "            return t!=1\n",
    "        return max(abs(sx-fx), abs(sy-fy))<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        m = max(abs(sx - fx), abs(sy - fy))\n",
    "        return m <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "\n",
    "        '''\n",
    "        (0, 1) (1,0), (1,1)\n",
    "        a + c = dy\n",
    "        b + c = dx\n",
    "        a+b+c = t\n",
    "        t = dy+dx-c\n",
    "        c = dy+dx-t\n",
    "        '''\n",
    "        dx = abs(fx-sx)\n",
    "        dy = abs(fy-sy)\n",
    "        if t== 1 and dx == 0 and dy == 0:\n",
    "            return False\n",
    "        \n",
    "        return t >= dx and t >= dy\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx = abs(fx - sx)\n",
    "        dy = abs(fy - sy)\n",
    "        min_l = max(dx, dy)\n",
    "        print(min_l)\n",
    "        if t >= min_l:\n",
    "            if min_l == 0 and t == 1:\n",
    "                return False\n",
    "            else:\n",
    "                return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        lenx = abs(sx-fx)\n",
    "        leny = abs(sy-fy)\n",
    "        mintime = abs(leny-lenx) + min(leny, lenx)\n",
    "        if mintime == 0:\n",
    "            if t == 1:\n",
    "                return False\n",
    "            else:\n",
    "                return True\n",
    "        if mintime > t:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx-fx), abs(sy-fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        row = abs(fx - sx)\n",
    "        col = abs(sy - fy)\n",
    "        if sx == fx and sy == fy:\n",
    "            return (t>=2 or t == 0)\n",
    "        # elif sx != fx:\n",
    "        else:\n",
    "            return t >= max(abs(fx - sx), abs(sy - fy))\n",
    "        # else:\n",
    "        #     return t >= abs(sy - fy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy==fy and t==1:\n",
    "            return False\n",
    "        return t>=max(abs(sx-fx),abs(sy-fy))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy ==fy:\n",
    "            return t !=1\n",
    "        return max(abs(sx-fx),abs(sy-fy))<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t!=1\n",
    "        mi = max(abs(sx - fx), abs(sy - fy))\n",
    "        return mi <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy :\n",
    "            return t != 1\n",
    "        return max(abs(sx-fx), abs(sy-fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        q1=abs(sx-fx)\n",
    "        q2=abs(sy-fy)\n",
    "        if t-q1>=0 and t-q2>=0:\n",
    "            if q1==0 and q2==0:\n",
    "                if t==1:\n",
    "                    return False\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        min_step = min(abs(sx-fx),abs(sy-fy)) + abs(abs(sx-fx)-abs(sy-fy))\n",
    "        if min_step > t or (min_step == 0 and t == 1):\n",
    "            return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if fx==sx and fy==sy: return t!=1\n",
    "        elif abs(fx-sx)<=t and abs(fy-sy)<=t: return True\n",
    "        else: return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return t >= max(abs(fx - sx), abs(fy - sy))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy==fy:\n",
    "            return t!=1\n",
    "        return max(abs(sx-fx),abs(sy-fy))<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if max(abs(fx-sx),abs(fy-sy)) == 0:\n",
    "            if t == 1:\n",
    "                return False\n",
    "            else:\n",
    "                return True\n",
    "        else:\n",
    "            return max(abs(fx-sx),abs(fy-sy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        '''\n",
    "        from collections import deque\n",
    "        qu=deque()\n",
    "        path=0\n",
    "        qu.append([sx,sy])\n",
    "        dx = [-1,-1,-1,0,1,1,1,0]\n",
    "        dy = [-1,0,1,1,1,0,-1,-1]\n",
    "        while qu:\n",
    "            k = len(qu)\n",
    "            path += 1\n",
    "            if path == t:\n",
    "                for _ in range(k):\n",
    "                    x,y = qu.popleft()\n",
    "                    for i in range(8):\n",
    "                        X,Y = x+dx[i],y+dy[i]\n",
    "                        if X == fx and Y == fy:\n",
    "                            return  True\n",
    "                return False\n",
    "            else:\n",
    "                for _ in range(k):\n",
    "                    x,y = qu.popleft()\n",
    "                    for i in range(8):\n",
    "                        X,Y = x+dx[i],y+dy[i]\n",
    "                        qu.append([X,Y])\n",
    "        '''\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        return t >= max(abs(fx-sx),abs(fy-sy))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx!=fx and sy!=fy:\n",
    "            min_ = abs(sx-fx)+abs(sy-fy)-min(abs(sx-fx),abs(sy-fy))\n",
    "            if t < min_:\n",
    "                return False\n",
    "            return True\n",
    "        elif sx==fx and sy==fy:\n",
    "            if t==1:\n",
    "                return False\n",
    "            return True\n",
    "        else:\n",
    "            min_ = abs(sx-fx)+abs(sy-fy)\n",
    "            if t < min_:\n",
    "                return False\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx,dy = abs(sx-fx), abs(sy-fy)\n",
    "        if dx==dy==0: return t!=1\n",
    "        mn = max(dx,dy)\n",
    "        return t>=mn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        width = abs(fy-sy)\n",
    "        hight = abs(fx-sx)\n",
    "        min_step = width+hight-min(width, hight)\n",
    "        if width == hight == 0 and t == 1:\n",
    "            return False\n",
    "        if min_step > t:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        s = (sx, sy)\n",
    "        f = (fx, fy)\n",
    "        l1 = abs(sx - fx)\n",
    "        l2 = abs(sy - fy)\n",
    "        min_time = max(l1, l2)\n",
    "        if min_time == 0:\n",
    "            if t == 1:\n",
    "                return False\n",
    "            return True\n",
    "        if min_time > t:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy :\n",
    "            if t == 1 :\n",
    "                return False\n",
    "            return True\n",
    "        return max(abs(fx - sx), abs(fy - sy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx = abs(fx - sx)\n",
    "        dy = abs(fy - sy)\n",
    "        if dx == 0 and dy == 0 and t == 1:\n",
    "            return False\n",
    "        return t >= max(dy, dx)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy==fy:\n",
    "            return t!=1\n",
    "        return max(abs(sx-fx), abs(sy-fy))<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\r\n",
    "        # 精簡版\r\n",
    "        minStep = abs(sx - fx) + abs(sy - fy) - min(abs(sx - fx), abs(sy - fy))\r\n",
    "        return False if (minStep > t) or (sx==fx and sy==fy and t-minStep==1) else True\r\n",
    "    \r\n",
    "        # 周賽時寫的\r\n",
    "        if minStep > t:\r\n",
    "            return False\r\n",
    "        if minStep == t:\r\n",
    "            return True\r\n",
    "        # 再來考慮增加步數的方法\r\n",
    "        diffStep = t - minStep\r\n",
    "        if diffStep > 1: # 因為必有兩步、三步的增加步數方法(繞圈圈)，所以只要大於1就一定可以\r\n",
    "            return True\r\n",
    "        else:\r\n",
    "            if min(abs(sx - fx), abs(sy - fy)) > 0: # 走一步斜的改成走兩步直的\r\n",
    "                return True\r\n",
    "            elif abs(sx - fx) > 0 or abs(sy - fy) > 0: # 走一步直的改成走兩步斜的\r\n",
    "                return True\r\n",
    "            else:\r\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        retVal = False\n",
    "\n",
    "        diffX = abs(fx - sx)\n",
    "        diffY = abs(fy - sy)\n",
    "\n",
    "        if (diffX == 0) and (diffY == 0):\n",
    "            if t != 1:\n",
    "                retVal = True\n",
    "        else:\n",
    "            if (t - min(diffX, diffY)) >= (max(diffX, diffY) - min(diffX, diffY)):\n",
    "                retVal = True\n",
    "\n",
    "        return retVal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        v = max(abs(sx - fx), abs(sy-fy))\n",
    "        if v == 0:\n",
    "            return t != 1\n",
    "        return v <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        step = min(abs(fx-sx), abs(fy-sy))\n",
    "        min_time = abs(fx-sx) + abs(fy-sy)-step\n",
    "        if min_time == 0 and t==1:\n",
    "            return False\n",
    "        if min_time>t:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        dx = abs(fx-sx)\n",
    "        dy = abs(fy-sy)\n",
    "        mi = max(dx,dy)\n",
    "        if mi==0:\n",
    "            return t!=1\n",
    "        return t>=mi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy and t == 1:\n",
    "            return False\n",
    "        mi = max(abs(sx - fx), abs(sy - fy))\n",
    "        return mi <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        width = abs(sx - fx)\n",
    "        height = abs(sy - fy)\n",
    "        if width == 0 and height == 0 and t == 1:\n",
    "            return False\n",
    "        return t >= max(width, height)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 根据分析，走斜线一次能前进2**0.5的距离>1的距离，因此最快的前进方式是走斜线，然后再走上下左右。\n",
    "# 从s到t走斜线的时间与在水平、竖直方向走直线的时间是一样的，因此其实只要计算以s与t为顶点的矩形长边长度即为最短从s到f的时间。只要t≥这个最短时间，就一定能到（多出来的时间可以围着f转圈）\n",
    "# 唯一的特殊情况是当s与f在同一点，同时t=1时，需要返回False\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if (sx, sy) == (fx, fy) and t == 1:\n",
    "            return False\n",
    "        dx = abs(sx - fx)\n",
    "        dy = abs(sy - fy)\n",
    "        return max(dx, dy) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx==fx and sy==fy and t==1:\n",
    "            return False\n",
    "        return max(abs(sx-fx),abs(sy-fy))<=t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        \n",
    "        return t >= max(abs(sx - fx),abs(sy - fy))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t!=1\n",
    "        return t >= max(abs(fx-sx), abs(fy-sy))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        retVal = False\n",
    "\n",
    "        diffX = abs(fx - sx)\n",
    "        diffY = abs(fy - sy)\n",
    "        if (diffX == 0) and (diffY == 0):\n",
    "            if t != 1:\n",
    "                retVal = True\n",
    "        else:\n",
    "            if (t - min(diffX, diffY)) >= (max(diffX, diffY) - min(diffX, diffY)):\n",
    "                retVal = True\n",
    "\n",
    "        return retVal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        thres = max(abs(sx-fx), abs(sy-fy))\n",
    "        return t >= thres if thres > 0 else t != 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        \n",
    "        high = abs(fx-sx) + abs(fy-sy)\n",
    "        low = max(abs(fx-sx), abs(fy-sy))\n",
    "        if t < low:\n",
    "            return False\n",
    "        if high == 0 and t == 1:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        return max(abs(sx - fx), abs(sy - fy)) <= t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        d = abs(sx - fx) + abs(sy - fy) - min(abs(sx - fx), abs(sy - fy))\n",
    "        return 0 < d <= t or (d == 0 and t != 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if(abs(sx-fx)>t or abs(sy-fy)>t):\n",
    "            return False\n",
    "        if(abs(sx-fx)==0 and t==1 and abs(sy-fy)==0):\n",
    "            return False\n",
    "        if (sx>=fx) and (sy>=fy):\n",
    "            if(abs(sx-fx)>abs(sy-fy)):\n",
    "                t-=abs(sy-fy)\n",
    "                sx-=abs(sy-fy)\n",
    "                sy=fy\n",
    "            else:\n",
    "                t-=abs(sx-fx)\n",
    "                sy-=abs(sx-fx)\n",
    "                sx=fx\n",
    "        elif (sx<fx) and (sy<fy):\n",
    "            if(abs(sx-fx)>abs(sy-fy)):\n",
    "                t-=abs(sy-fy)\n",
    "                sx+=abs(sy-fy)\n",
    "                sy=fy\n",
    "            else:\n",
    "                t-=abs(sx-fx)\n",
    "                sy+=abs(sx-fx)\n",
    "                sx=fx\n",
    "        elif (sx<fx) and (sy>=fy):\n",
    "            if(abs(sx-fx)>abs(sy-fy)):\n",
    "                t-=abs(sy-fy)\n",
    "                sx+=abs(sy-fy)\n",
    "                sy=fy\n",
    "            else:\n",
    "                t-=abs(sx-fx)\n",
    "                sy-=abs(sx-fx)\n",
    "                sx=fx\n",
    "        elif (sx>=fx) and (sy<fy):\n",
    "            if(abs(sx-fx)>abs(sy-fy)):\n",
    "                t-=abs(sy-fy)\n",
    "                sx-=abs(sy-fy)\n",
    "                sy=fy\n",
    "            else:\n",
    "                t-=abs(sx-fx)\n",
    "                sy+=abs(sx-fx)\n",
    "                sx=fx\n",
    "\n",
    "\n",
    "        if(abs(sx-fx)==0):\n",
    "            return t>=abs(sy-fy)\n",
    "        else:\n",
    "            return t>=abs(sx-fx)\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        min_dis = max(abs(fx - sx), abs(fy - sy))\n",
    "        if t < min_dis:\n",
    "            return False\n",
    "        elif t == 1 and min_dis == 0:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n",
    "        if sx == fx and sy == fy:\n",
    "            return t != 1\n",
    "        x_sub = abs(sx-fx)\n",
    "        y_sub = abs(sy-fy)\n",
    "        if max(x_sub, y_sub) <= t:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
